//
//  TableViewControllerDataSource.swift
//  TodoItemDemo
//
//  Created by alex on 2017/7/31.
//  Copyright © 2017年 RoseVision. All rights reserved.
//

import UIKit

let inputCellReuseId = "inputCell"
let todoCellResueId = "todoCell"

class TableViewControllerDataSource: NSObject,
UITableViewDataSource {
    enum Section: Int {
        case input = 0, todos, max
    }

    // updaate
    // updaate2
    // updaate master
    // updaate3 master
// dsd
    //df 
    var todos: [String]
    weak var owner: LRTableViewController?
    init(todos:[String], owner: LRTableViewController?) {
        self.todos = todos
        self.owner = owner
    }
    
     func numberOfSections(in tableView: UITableView) -> Int {
        return Section.max.rawValue
    }
    
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        guard let section = Section(rawValue: section) else {
            fatalError()
        }
        switch section {
        case .input:
            return 1
        case .todos:
            return todos.count
        case .max:
            fatalError()
        }
        
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let section = Section(rawValue: indexPath.section) else {
            fatalError()
        }
        
        switch section {
        case .input:
            let cell = tableView.dequeueReusableCell(withIdentifier: inputCellReuseId, for: indexPath) as! LRTableViewCell
            cell.delegate = owner;
            return cell
        case .todos:
            let cell = tableView.dequeueReusableCell(withIdentifier: todoCellResueId, for: indexPath)
            cell.textLabel?.text = todos[indexPath.row]
            return cell
        default:
            fatalError()
        }
    }
    
    
}
